<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="./js/jquery/jquery.js"></script>
<script src="./js/common/common.js"></script>
<script src="./js/common/errorCodeHandler.js"></script>

<body>
<form id="form">
    <span style="width: 60px;display: inline-block;">用户名:</span>
    <input type="text" id="username" name="username" value="plat_user">
    <br>

    <span style="width: 60px;display: inline-block;">密码:</span>
    <input type="text" id="password" name="password" value="yyyL-001">
    <br>

    <span style="width: 60px;display: inline-block;">验证码:</span>
    <input type="text" id="verificationCode" name="verificationCode" value="1234">
    <img id="verificationImg" src="/study/login/getVerifyCode" style="height:33px;cursor:pointer;" onclick="this.src=this.src">

    <input style="margin-left: 10px;" type="submit" value="登录"/>
    <input type="checkbox" id="remember-me" name="remember-me">记住我
</form>

<a href="/static/anonymous_home.html">匿名访问</a>

</body>
<script>
    $("#form").submit(function(e){
        e.preventDefault(); // 阻止表单默认提交行为
        var username = $("#username").val();
        var password = $("#password").val();
        var verificationCode = $("#verificationCode").val();
        var remember_me = $("#remember-me").val();

        var param = {
            username: username,
            password: password,
            verificationCode: verificationCode,
            'remember-me': remember_me
        }

        $.ajax({
            type: "POST",
            url: "/study/login/userLogin",
            data: param,
            success: function (result, status, xhr) {
                if(!errorFilterHandler(result)){
                    return;
                }
                window.location.href = '/static/home.html';
            },
            // 失败时触发
            error: function (xhr, status, error) {
                console.log("请求失败触发，status:" + status);
            }
        });
    })


</script>
</html>
